const sum = function (a, b, c, d) {
  return a + b + c + d;
};

// const data = sum(1, 2);
// console.log(data);

const curry = function (fn) {
  return function helper(...args) {
    if (args.length >= fn.length) { //fn.length代表原始函数的参数数量
      return fn(...args);
    } else {
      return function (...args2) {
        return helper(...args, ...args2);
      };
    }
  };
};

// const sum2 = curry(sum);
// const data = sum2(1)(2)(3)(4);
// console.log(data);

// const data2 = sum2(1)(2)(3, 4);
// console.log(data2);

// const data3 = sum2(1, 2)(3, 4);
// console.log(data3);

// const data4 = sum2(1, 2, 3)(4);
// console.log(data4);

function check(reg, txt) {
  return reg.test(txt)
}

var curryCheck = curry(check);

var hasNumber = curryCheck(/\d+/g);

console.log(hasNumber('test'));
console.log(hasNumber('test1'));

var hasLetter = curryCheck(/[a-z]+/g);
console.log(hasLetter('test'));
console.log(hasLetter('132'));

